import axios from "axios"
import store from "../store.js"
import { Loading } from 'element-ui';
const $request = axios.create({
    baseURL:"https://netease.bluej.cn",
    timeout: 50000,
    withCredentials: true
})
let loading = null;
//请求拦截
$request.interceptors.request.use(
    function (config) {
        loading = Loading.service({text:"拼命加载中"});
        let token = store.state.token;
        // if (token) {
        //     config.headers.Authorize = token  
        // }
        return config
    },
    function (error) {
        return Promise.reject(error)
    }
)
//$request.interceptors.request.use(
//	function(config) {
//
//		loading = Loading.service({
//			text: "拼命加载中"
//		});
//
//		return config
//	},
//	function(error) {
//		return Promise.reject(error)
//	}
//)

//响应拦截
$request.interceptors.response.use(
	function(response) {
		if(loading) {
			loading.close();
		}
		return response
	},
	function(error) {
		return Promise.reject(error)
	}
)
export default $request;